<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">
    <link rel="stylesheet" href="${assets}/plugins/ztree/zTreeStyle/metro.css" type="text/css">
    <!--[if IE 8]>
	<link rel="stylesheet" href="${newframe}/css/base/IE8.css" type="text/css"/>
	<![endif]-->
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${assets}/js/jquery.serializejson.js"></script>
    <script src="${assets}/plugins/ztree/jquery.ztree.all-3.5.min.js"></script>

    <script type="text/javascript">
        var setting = {
            check: {
                enable: true,
                chkboxType : {"Y": "ps", "N": "ps"}
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                beforeClick: beforeClick,
                onCheck:onCheck
            }
        };


        var zNodes = ${menuList};

        var code;

        function setCheck() {
            var zTree = $.fn.zTree.getZTreeObj("menuTree");
        }
        var className = "dark";
        function beforeClick(treeId, treeNode, clickFlag) {
            var zTree = $.fn.zTree.getZTreeObj("menuTree");
            zTree.checkNode(treeNode, !treeNode.checked, null, true);
            return false;
        }

        $(document).ready(function(){
            $.fn.zTree.init($("#menuTree"), setting, zNodes);
            setCheck();
        });
        function onCheck(e,treeId,treeNode){
            var treeObj=$.fn.zTree.getZTreeObj("menuTree"),
                nodes=treeObj.getCheckedNodes(true),
                v="";

            var _menuList = new Array();
            for(var i=0;i<nodes.length;i++){
                v+=nodes[i].name + ",";
                console.log(nodes[i].id); //获取选中节点的值
                _menuList[i] = nodes[i].id;
            }

            $("#menuIdList").val(_menuList);

        }
        //-->
    </script>
    <script>
        $(document).ready(function () {
            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    roleName: {
                        validators: {
                            notEmpty: true
                        }
                    }
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();

                var _url = "";
                debugger;
                if ($("#roleId").val() == null || $("#roleId").val() == '') {
                    _url = '${URL_SYS_ROLE_LIST_ADD}';
                } else {
                    _url = '${URL_SYS_ROLE_LIST_UPDATE}';
                }

                $.ajax({
                    url: _url,
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    error: function (data) {
                        console.log("error=================" + data);
                        console.log(data);
                        console.log("error=================" + data);
                        alert('error');
                    },
                    success: function (data) {
                        closeFrame();
                    }
                });

            });
        });
        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }
    </script>
</head>
<body style="width: 98%">
<form id="myForm" class="form-horizontal" method="post">
    <input type="hidden" id="roleId" name="roleId" value="${entity.roleId}"/>
    <div class="clearfix">
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">角色名称</label>
            <div class="col-sm-8">
                <input type="text" id="roleName" name="roleName" class="form-control" value="${entity.roleName}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">备注</label>
            <div class="col-sm-8">
                <input type="text" id="remark" name="remark" class="form-control" value="${entity.remark}">
            </div>
        </div>

        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">授权</label>
            <div class="col-sm-8">
                <ul id="menuTree" class="ztree"></ul>
            </div>
        </div>
        <input type="hidden" name="menuIdList" id="menuIdList">

    </div>
    <div class="modal-footer" style="text-align: center;padding-bottom:70px; ">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">
            关闭
        </button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>
</body>
</html>